<?php
class App_Order_Goods 
{
    public static function updateCountsSale ($orderNo)
    {
        $query = DB::select('g.goodsId')
            ->from(array('app_order', 'o'))
            ->join(array('app_order_goods', 'g'), 'LEFT')
            ->on('o.id', '=', 'g.orderId')
            ->where('o.orderNo', '=', $orderNo)
            ->execute();

        $goods = array();
        foreach ($query as $rs)
        {
            $goodsId  = $rs['goodsId'];

            if (! in_array($goodsId, $goods))
                $goods[] = $goodsId;
        }

        foreach ($goods as $goodsId)
        {
            App_Goods::syncCountsSale($goodsId);    
        }
    }
}
